﻿using System.Data;
using System.Data.SqlClient;

namespace AbstractSql {
    class _AbsDBCommand : IAbsDBCommand {
        internal string connectionName;
        SqlConnection sqlConnection;
        internal _AbsDBCommand() {
        }
        internal _AbsDBCommand(string connectionName) {
            this.connectionName = connectionName;
        }
        internal _AbsDBCommand(SqlConnection connection) {
            this.sqlConnection = connection;
        }
        IAbsDBCommandExecution GetCommand(CommandType commandType, string commandText) {
            AbsDBCommandExecution ce;
            if (sqlConnection != null)
                ce = new AbsDBCommandExecution(sqlConnection);
            else
                ce = new AbsDBCommandExecution(connectionName);
            ce.CommandType = commandType;
            ce.CommandText = commandText;
            return ce;
        }
        public IAbsDBCommandExecution SqlCommand(string query) {
            return GetCommand(CommandType.Text, query);
        }
        public IAbsDBCommandExecution StoredProc(string storedProcName) {
            return GetCommand(CommandType.StoredProcedure, storedProcName);
        }
    }
}